
export class ActionSerialQueue {
  fns: Function[] = [];
  isRunning: boolean = false;
  addAction(action: Function) {
    console.log("addAction");
    if (this.fns.length == 0) {
      let fn = Promise
        await action();
        console.log(`finish one,length is: ${this.fns.length}`)
        this.fns.pop();
        if (this.fns.length) {
          let fn = this.fns[0];
          await fn();
        }
      }
      this.fns.push(fn);
      fn();
    }
    else {
      let fn = async () => {
        await action();
        console.log(`finish one,length is: ${this.fns.length}`)
        this.fns.pop();
        if (this.fns.length) {
          let fn = this.fns[0];
          await fn();
        }
      }
      this.fns.push(fn);
    }
  }
}

let queue = new ActionSerialQueue();
queue.addAction(() => { console.log(1) });
queue.addAction(() => { console.log(2) });
queue.addAction(() => { console.log(3) });
// queue.start();